package contstat;

import java.awt.CardLayout;
import javax.swing.DefaultListModel;
import javax.swing.SwingWorker;

public class InstallDialog extends javax.swing.JDialog {

    public String Result = "Exit";
    private CardLayout Layout;
    private String NextButtonAction = "";

    public InstallDialog(java.awt.Frame parent, boolean modal, boolean NeedSetup, boolean NeedTblInstall, boolean NeedTblUpdate) {
        super(parent, modal);
        initComponents();

        jLabel11.setText("NeedSetup = " + String.valueOf(NeedSetup) + ", NeedTblInstall = " + String.valueOf(NeedTblInstall) + ", NeedTblUpdate = " + String.valueOf(NeedTblUpdate));

        Layout = (CardLayout) jPanel1.getLayout();

        if (NeedTblInstall && NeedSetup) {
            jLabel1.setText("Первый запуск программы на данном рабочем месте.");
            jButton3.setText("Далее >>");
            jButton4.setText("<< Назад");
            jButton3.setEnabled(true);
            jButton4.setEnabled(false);
            this.NextButtonAction = "NextSetupInstall";
            Layout.show(jPanel1, "card2");
        }

        if (NeedTblInstall && !NeedSetup) {
            jLabel1.setText("Сервер баз данных не найден! Возможно он выключен или перенесен.");
            jButton3.setText("Далее >>");
            jButton4.setText("<< Назад");
            jButton3.setEnabled(true);
            jButton4.setEnabled(false);
            this.NextButtonAction = "NextSetupInstall";
            Layout.show(jPanel1, "card2");
        }

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jLabel11 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jPasswordField1 = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jPanel10 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jProgressBar1 = new javax.swing.JProgressBar();
        jPanel8 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Установка и настройка программы");
        setResizable(false);

        jButton1.setText("Выход");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel1.setLayout(new java.awt.CardLayout());

        jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD));
        jLabel1.setText("Вы запускаете программу в первый раз.");

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Выберите необходимое действие:"));

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Установка новой базы данных");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Подключение к существующей базе данных");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButton2)
                    .addComponent(jRadioButton1))
                .addContainerGap(261, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jRadioButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel11.setText("jLabel11");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel11)
                    .addComponent(jLabel1))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 140, Short.MAX_VALUE)
                .addComponent(jLabel11)
                .addContainerGap())
        );

        jPanel1.add(jPanel2, "card2");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Параметры подключения к серверу"));

        jLabel2.setText("Имя или адрес MySQL сервера:");

        jTextField1.setText("localhost:3306");

        jLabel5.setText("Имя пользователя с правами root:");

        jTextField2.setText("root");

        jLabel6.setText("Пароль пользователя с правами root:");

        jPasswordField1.setText("msspassw");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel3.setText("Установка новой базы данных.");

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Параметры новой базы данных"));

        jLabel7.setText("Название базы данных:");

        jTextField3.setText("contractsdb");

        jLabel8.setText("Имя пользователя для доступа к базе данных:");

        jLabel9.setText("Пароль для доступа к базе данных:");

        jTextField4.setText("contracts");

        jTextField5.setText("contracts");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel3)
                    .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.add(jPanel3, "card3");

        jLabel4.setText("Подключение к базе данных.");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addContainerGap(424, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addContainerGap(272, Short.MAX_VALUE))
        );

        jPanel1.add(jPanel4, "card4");

        jLabel10.setText("Установка новой базы данных.");

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 623, Short.MAX_VALUE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 623, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel10)
                .addGap(18, 18, 18)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel1.add(jPanel10, "card7");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 647, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 299, Short.MAX_VALUE)
        );

        jPanel1.add(jPanel8, "card6");

        jButton2.setText("Skip");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Далее >>");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("<< Назад");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 247, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap())
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Result = "Exit";
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        Result = "Skip";
        dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        if (this.NextButtonAction.equals("NextSetupInstall")) {
            if (jRadioButton1.isSelected()) {
                jButton3.setText("Далее >>");
                jButton4.setText("<< Назад");
                jButton3.setEnabled(true);
                jButton4.setEnabled(true);
                this.NextButtonAction = "NextInstallStep1";
                Layout.show(jPanel1, "card3");
                return;
            } else {
                jButton3.setText("Далее >>");
                jButton4.setText("<< Назад");
                jButton3.setEnabled(true);
                jButton4.setEnabled(true);
                this.NextButtonAction = "NextSetupStep1";
                Layout.show(jPanel1, "card4");
                return;
            }
        }
        if (this.NextButtonAction.equals("NextInstallStep1")) {
            this.NextButtonAction = "NextInstallStep2";
            Layout.show(jPanel1, "card7");
            jButton3.setEnabled(false);
            jButton4.setEnabled(false);
            MakeInstall();
            return;
        }
        if (this.NextButtonAction.equals("NextInstallStep2")) {
            this.NextButtonAction = "NextInstallStep3";
            Layout.show(jPanel1, "card6");
            return;
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void MakeInstall() {

        new SwingWorker() {

            boolean ic = false;

            @Override
            protected void done() {
                super.done();
                if (ic) {
                    jButton3.setEnabled(true);
                    jButton4.setEnabled(false);
                } else {
                    jButton3.setEnabled(false);
                    jButton4.setEnabled(true);
                }
            }

            @Override
            protected Object doInBackground() throws Exception {
                DefaultListModel lm = new DefaultListModel();
                jList1.setModel(lm);

                jProgressBar1.setMinimum(0);
                jProgressBar1.setMaximum(7);
                jProgressBar1.setValue(0);

                Vars.prop.setProperty("Username", jTextField2.getText());
                Vars.prop.setProperty("Userpass", new String(jPasswordField1.getPassword()));
                Vars.prop.setProperty("DB_URL", "jdbc:mysql://" + jTextField1.getText());

                DB db = new DB();
                int err;

                lm.addElement("Создание базы данных " + jTextField3.getText() + " на сервере " + jTextField1.getText() + "...");
                err = db.executeNonQuery("CREATE DATABASE IF NOT EXISTS " + jTextField3.getText());
                if (err == 0) {
                    lm.addElement("База данных успешно создана!");
                } else {
                    lm.addElement("Ошибка создания базы данных!");
                    return null;
                }
                jProgressBar1.setValue(jProgressBar1.getValue() + 1);

                lm.addElement("Создание пользователя " + jTextField4.getText() + "...");
                err = db.executeNonQuery("CREATE USER \"" + jTextField4.getText() + "\"@\"%\" IDENTIFIED BY \"" + jTextField5.getText() + "\"");
                if (err == 0) {
                    lm.addElement("Пользователь успешно создан!");
                } else {
                    lm.addElement("Ошибка создания пользователя!");
                    return null;
                }
                err = db.executeNonQuery("GRANT ALL ON " + jTextField3.getText() + ".* TO \"" + jTextField4.getText() + "\"@\"%\"");
                if (err != 0) {
                    lm.addElement("Ошибка добавления привилегий!");
                    return null;
                }
                jProgressBar1.setValue(jProgressBar1.getValue() + 1);

                lm.addElement("Создание таблицы \"contracts\"...");
                err = db.executeNonQuery("CREATE TABLE IF NOT EXISTS `contractsdb`.`contracts` ("
                        + "`k` INT NOT NULL AUTO_INCREMENT, "
                        + "`d` TINYINT(1) NOT NULL, "
                        + "`c` DATETIME NOT NULL, "
                        + "`contract_type_id` INT NOT NULL, "
                        + "`contract_org_name` VARCHAR(4096) NOT NULL, "
                        + "`contract_name_and_num` VARCHAR(4096) NOT NULL, "
                        + "`contract_description` TEXT NOT NULL, "
                        + "`contract_end_date` DATETIME NOT NULL, "
                        + "`contract_sum` DOUBLE NOT NULL, "
                        + "`contract_advance` DOUBLE NOT NULL, "
                        + "`contract_kreditdebt_id` INT NOT NULL, "
                        + "`contract_notes` TEXT NOT NULL, "
                        + "`contract_owner_id` INT NOT NULL, "
                        + "PRIMARY KEY (`k`)) "
                        + "ENGINE = InnoDB "
                        + "DEFAULT CHARACTER SET = utf8");
                if (err == 0) {
                    lm.addElement("Таблица \"contracts\" успешно создана!");
                } else {
                    lm.addElement("Ошибка при создании таблицы \"contracts\"!");
                    return null;
                }
                jProgressBar1.setValue(jProgressBar1.getValue() + 1);

                lm.addElement("Создание таблицы \"contrtypes\"...");
                err = db.executeNonQuery("CREATE TABLE IF NOT EXISTS `contractsdb`.`contrtypes` ("
                        + "`k` INT NOT NULL, "
                        + "`d` TINYINT(1) NOT NULL, "
                        + "`c` DATETIME NOT NULL, "
                        + "`contrtype_name` VARCHAR(1024) NOT NULL, "
                        + "PRIMARY KEY (`k`)) "
                        + "ENGINE = InnoDB "
                        + "DEFAULT CHARACTER SET = utf8");
                if (err == 0) {
                    lm.addElement("Таблица \"contrtypes\" успешно создана!");
                } else {
                    lm.addElement("Ошибка при создании таблицы \"contrtypes\"!");
                    return null;
                }
                jProgressBar1.setValue(jProgressBar1.getValue() + 1);

                lm.addElement("Создание таблицы \"payments\"...");
                err = db.executeNonQuery("CREATE TABLE IF NOT EXISTS `contractsdb`.`payments` ("
                        + "`k` INT NOT NULL AUTO_INCREMENT, "
                        + "`d` TINYINT(1) NOT NULL, "
                        + "`c` DATETIME NOT NULL, "
                        + "`contract_id` INT NOT NULL, "
                        + "`period_name` VARCHAR(1024) NOT NULL, "
                        + "`obligation_budget` DOUBLE NOT NULL, "
                        + "`obligation_vnebudget` DOUBLE NOT NULL, "
                        + "`obligation_dop` DOUBLE NOT NULL, "
                        + "`payment_budget` DOUBLE NOT NULL, "
                        + "`payment_vnebudget` DOUBLE NOT NULL, "
                        + "`payment_notes` TEXT NOT NULL, "
                        + "PRIMARY KEY (`k`)) "
                        + "ENGINE = InnoDB "
                        + "DEFAULT CHARACTER SET = utf8");
                if (err == 0) {
                    lm.addElement("Таблица \"payments\" успешно создана!");
                } else {
                    lm.addElement("Ошибка при создании таблицы \"payments\"!");
                    return null;
                }
                jProgressBar1.setValue(jProgressBar1.getValue() + 1);

                lm.addElement("Создание таблицы \"users\"...");
                err = db.executeNonQuery("CREATE TABLE IF NOT EXISTS `contractsdb`.`users` ("
                        + "`k` INT NOT NULL, "
                        + "`d` TINYINT(1) NOT NULL, "
                        + "`c` DATETIME NOT NULL, "
                        + "`user_name` VARCHAR(1024) NOT NULL, "
                        + "`user_description` TEXT NOT NULL, "
                        + "PRIMARY KEY (`k`)) "
                        + "ENGINE = InnoDB "
                        + "DEFAULT CHARACTER SET = utf8");
                if (err == 0) {
                    lm.addElement("Таблица \"users\" успешно создана!");
                } else {
                    lm.addElement("Ошибка при создании таблицы \"users\"!");
                    return null;
                }
                jProgressBar1.setValue(jProgressBar1.getValue() + 1);

                lm.addElement("Создание таблицы \"logs\"...");
                err = db.executeNonQuery("CREATE TABLE IF NOT EXISTS `contractsdb`.`logs` ("
                        + "`k` INT NOT NULL, "
                        + "`c` DATETIME NOT NULL, "
                        + "`log_type` VARCHAR(45) NOT NULL, "
                        + "`log_text` TEXT NOT NULL, "
                        + "`log_user_id` INT NOT NULL, "
                        + "PRIMARY KEY (`k`)) "
                        + "ENGINE = InnoDB "
                        + "DEFAULT CHARACTER SET = utf8");
                if (err == 0) {
                    lm.addElement("Таблица \"logs\" успешно создана!");
                } else {
                    lm.addElement("Ошибка при создании таблицы \"logs\"!");
                    return null;
                }
                jProgressBar1.setValue(jProgressBar1.getValue() + 1);

                ic = true;

                Vars.prop.setProperty("DB_URL", "jdbc:mysql://" + jTextField1.getText() + "/" + jTextField3.getText());
                Vars.SaveProperties();

                return null;
            }
        }.execute();
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        if (this.NextButtonAction.equals("NextInstallStep1") || this.NextButtonAction.equals("NextSetupStep1")) {
            jButton3.setText("Далее >>");
            jButton4.setText("<< Назад");
            jButton3.setEnabled(true);
            jButton4.setEnabled(false);
            this.NextButtonAction = "NextSetupInstall";
            Layout.show(jPanel1, "card2");
            return;
        }
        if (this.NextButtonAction.equals("NextInstallStep2")) {
            jButton3.setText("Далее >>");
            jButton4.setText("<< Назад");
            jButton3.setEnabled(true);
            jButton4.setEnabled(true);
            this.NextButtonAction = "NextInstallStep1";
            Layout.show(jPanel1, "card3");
            return;
        }
    }//GEN-LAST:event_jButton4ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    // End of variables declaration//GEN-END:variables
}
